package aex.service;



import java.io.Serializable;
import java.util.LinkedHashMap;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import aex.dao.ShowBoxDao;
import aex.domain.ShowBox;
import aex.util.PageBean;



@Transactional(readOnly = false)
@Service(ShowBoxService.SERVICE_NAME)

public class ShowBoxService  {

	
	public static final String SERVICE_NAME="aex.service.ShowBoxService";
	/**
	 * 以注解的形式让spring为我们注入dao的实现类
	 */
	@Resource(name = ShowBoxDao.SERVICE_NAME)
	public ShowBoxDao dao;
	
	public ShowBoxService() {
		
	}


	
	

	/**
	 * 通过展位名称查询出一个展位，要求数据库中的展位名称是不重复的
	 * @param name
	 * @return
	 */
	public ShowBox findBoxByName(String name) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.sbName", "asc");
		return dao.findCollectionByConditionNoPage("and tName.sbName='"+name+"'", null, orderby).get(0);
	}


	/**
	 * 找到所有的图集展位
	 * @return
	 */
	public List<ShowBox> findAllAlbumBox() {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.sbName", "asc");
		return dao.findCollectionByConditionNoPage("and tName.sbType='图集'", null, orderby);
	}
	/**
	 * 找到所有的文章展位
	 * @return
	 */
	public List<ShowBox> findAllArticleBox() {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.sbName", "asc");
		return dao.findCollectionByConditionNoPage("and tName.sbType='文章'", null, orderby);
	}
	
	
	
	public ShowBox findByID(Serializable id) {
		return dao.findObjectByID(Integer.parseInt(id+""));
	}
	
	public void deleteById(Serializable id) {
		dao.deleteObjectByIDs(Integer.parseInt(id+""));
	}
	
	public void save(ShowBox obj) {
		dao.save(obj);
	}
	public void update(ShowBox obj) {
		dao.merge(obj);
	}




	
	public  PageBean<ShowBox> findAllBox(PageBean<ShowBox> pageBean) {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.sbName", "asc");
		return dao.findPageBean(" ", null, orderby, pageBean);
	}

	public  List<ShowBox> findAllBox() {
		LinkedHashMap<String, String> orderby=new LinkedHashMap<String, String>();
		orderby.put("tName.sbName", "asc");
		return dao.findCollectionByConditionNoPage(" ", null, orderby);
	}



	
	


}
